document.querySelector('.img__btn').addEventListener('click', function() {
    document.querySelector('.content').classList.toggle('s--signup')
});


//以下为jquery代码
//实现用户注册提示以及ajax请求
$('#username').click(function(){
    $("#info").css("display","block");
    $("#msg").html("<p>字母开头</p><p>允许5-16字节</p><p>允许字母数字下划线</p>");
    window.setTimeout(function(){
        $("#info").css("display","none");
    },2500);
});
$('#username').blur(function(){
    var reg = /^[a-zA-Z][a-zA-Z0-9_]{4,15}$/;
    if(reg.test($("#username").val())){
        $("#usernameHint").css("color","#5FB878");
        $("#usernameJudge").val(1);
        return true;
    }else{
        $("#usernameHint").css("color","#FF0000");
        $("#usernameJudge").val(0);
        return false;
    }
});

$('#mobile').click(function(){
    $("#info").css("display","block");
    $("#msg").html("<p>请输入十一位有效数字</p><p>开头数字为13,14,15,18</p>");
    window.setTimeout(function(){
        $("#info").css("display","none");
    },2500);
});
$('#mobile').blur(function(){
    var reg = /^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
    if(reg.test($("#mobile").val())){
        $("#mobileHint").css("color","#5FB878");
        $("#mobileJudge").val(1);
        return true;
    }else{
        $("#mobileHint").css("color","#FF0000");
        $("#mobileJudge").val(0);
        return false;
    }
});

$('#password').click(function(){
    $("#info").css("display","block");
    $("#msg").html("<p>以字母开头</p><p>长度在6-18之间</p><p>只能包含字母数字和下划线</p>");
    window.setTimeout(function(){
        $("#info").css("display","none");
    },2500);
});
$('#password').blur(function(){
    var reg = /^[a-zA-Z]\w{5,17}$/;
    if(reg.test($("#password").val())){
        $("#passwordHint").css("color","#5FB878");
        $("#passwordJudge").val(1);
        return true;
    }else{
        $("#passwordHint").css("color","#FF0000");
        $("#passwordJudge").val(0);
        return false;
    }
});

$("#register").click(function(){
    var usernameJudge = $("#usernameJudge").val();
    var mobileJudge = $("#mobileJudge").val();
    var passwordJudge = $("#passwordJudge").val();

    if(usernameJudge!="1"||mobileJudge!="1"|| passwordJudge!="1"){
        $("#info").css("display","block");
        $("#msg").html("<p>请按照要求填写</p>");
        window.setTimeout(function(){
            $("#info").css("display","none");
        },1500);
        return false;
    }
    $.post("/userRegister",{"username":$('#username').val(),"password":$('#password').val(),"mobile":$('#mobile').val()},function (data) {
        if(data==1){
            window.location.href="login";
        }else{
            alert(data);
        }
    });
});

$("#login").click(function(){
    var user = new Object();
    user.username = $("#loginName").val();
    user.password = $("#loginPassword").val();
    $.post("/userLogin",user,function (data) {
        if(data==1){
            window.location.href="index-member";
        }else{
            $("#info").css("display","block");
            $("#msg").html("<p>账号或密码错误</p>");
            window.setTimeout(function(){
                $("#info").css("display","none");
            },1500);
            return false;
        }
    });
});
